/**
  ******************************************************************************
  * @file    task_cfg.h 
  * @author  Feirui_Joe
  * @version V0.1
  * @date    07/26/2010
  * @brief   OS Task and Event Management
  ******************************************************************************
  * @copy
  *
  * <h2><center>&copy; COPYRIGHT 2010 Feirui</center></h2>
  */ 

#ifndef  __TASK_CFG_H__
#define  __TASK_CFG_H__


#ifdef __cplusplus
 extern "C" {
#endif



/**
  * @brief  Debug Test
  */
#ifdef DISABLE_DEBUG_OPT
#define SYS_DebugERROR                      
#else
#define SYS_DebugERROR       while(MCUFaultFlag)
#endif

#define TimeDlyInfinity      ((uint32_t)0)


/**
  * @brief  Tasks Management.
  */
/*$PAGE*//**
  * @brief  INCLUDE FILES.
  */
#include	  <app_boot.h>
#include	  <app_start.h>   
#include    <app_comm.h>    
#include    <app_hci.h>         
#include	  <app_dstin.h>   
#include	  <app_normad.h>  
#include    <app_acad.h>    
#include    <app_Workflow.h>
#include    <app_load.h>     
#include    <app_relay.h>   
#include    <app_network.h>   



/*$PAGE*/
#define TaskStartSyncNumber   9+2

                 /**************TASK define******************/

                              /* Priority */
/**
  * @brief TASK PRIORITIES definition
  */
/* #define  OS_TASK_Idle_PRIO               (OS_LOWEST_PRIO - 0)   */
/* #define  OS_TASK_Stat_PRIO               (OS_LOWEST_PRIO - 1)   */
/* #define  Reserve4_PRIO                   (OS_LOWEST_PRIO - 2)   */
/* #define  Reserve5_PRIO                   (OS_LOWEST_PRIO - 3)   */
/* #define  Reserve6_PRIO                   (OS_LOWEST_PRIO - 4)   */


/*#define  OS_TASK_TMR_PRIO                 24       */
#define  APP_TASK_PRIO_START                25        /* Memory Task        */
#define  APP_TASK_PRIO_COMM                 23        /* Communicate Task   */
#define  APP_TASK_PRIO_HCI                  22        /* HCI Task           */
#define  APP_TASK_PRIO_DSTIN                16        /* Digital Input Task */
#define  APP_TASK_PRIO_NORMAD               20        /* Normal AD Task     */
#define  APP_TASK_PRIO_ACAD                 21        /* AC AD Task         */
#define  APP_TASK_PRIO_WORKFLOW             17        /* Workflow Task      */
#define  APP_TASK_PRIO_LOAD                 18        /* Load  Task         */
#define  APP_TASK_PRIO_RELAY                19        /* Relay Task         */
#define  APP_TASK_PRIO_WIFI                 13        /* WIFI Task          */
#define  APP_TASK_PRIO_NETWORK_HandleCache  14        /* ec20 cache handle Task          */
#define  APP_TASK_PRIO_NETWORK_HandleSerData  15      /* ec20 handle serverData          */

#define  App_Mutex_PRIO_SETCFG              12

/* #define  Reserve3_PRIO                    3       */
/* #define  Reserve2_PRIO                    2       */
/* #define  Reserve1_PRIO                    1       */
/* #define  Reserve0_PRIO                    0       */

                              /* TASK STACK */
/**
  * @brief TASK STACK SIZES definition
  *        Size of the task stacks (# of OS_STK entries)
  */
#define  APP_TASK_STK_SIZE_START                         260
#define  APP_TASK_STK_SIZE_COMM                          170
#define  APP_TASK_STK_SIZE_HCI                           170
#define  APP_TASK_STK_SIZE_DSTIN                         170
#define  APP_TASK_STK_SIZE_NORMAD                        170
#define  APP_TASK_STK_SIZE_ACAD                          260
#define  APP_TASK_STK_SIZE_WORKFLOW                      170
#define  APP_TASK_STK_SIZE_LOAD                          170
#define  APP_TASK_STK_SIZE_RELAY                         170
#define  APP_TASK_STK_SIZE_WIFI                          200
#define  APP_TASK_STK_SIZE_HandleCache                   150
#define  APP_TASK_STK_SIZE_HandleSerData                 150


/**
  * @brief STACK definition
  */
APP_EXT_START     OS_STK    App_TaskStk_START   [APP_TASK_STK_SIZE_START   ];
APP_EXT_COMM      OS_STK    App_TaskStk_COMM    [APP_TASK_STK_SIZE_COMM    ];
APP_EXT_HCI       OS_STK    App_TaskStk_HCI     [APP_TASK_STK_SIZE_HCI     ];
APP_EXT_DSTIN     OS_STK    App_TaskStk_DSTIN   [APP_TASK_STK_SIZE_DSTIN   ];
APP_EXT_NORMAD    OS_STK    App_TaskStk_NORMAD  [APP_TASK_STK_SIZE_NORMAD  ];
APP_EXT_ACAD      OS_STK    App_TaskStk_ACAD    [APP_TASK_STK_SIZE_ACAD    ];
APP_EXT_WORKFLOW  OS_STK    App_TaskStk_WORKFLOW[APP_TASK_STK_SIZE_WORKFLOW];
APP_EXT_LOAD      OS_STK    App_TaskStk_LOAD    [APP_TASK_STK_SIZE_LOAD    ];
APP_EXT_RELAY     OS_STK    App_TaskStk_RELAY   [APP_TASK_STK_SIZE_RELAY   ];
APP_EXT_NETWORK   OS_STK    App_TaskStk_WIFI    [APP_TASK_STK_SIZE_WIFI    ];
APP_EXT_START     OS_STK    App_TaskStk_HandleCache    [APP_TASK_STK_SIZE_HandleCache    ];
APP_EXT_START     OS_STK    App_TaskStk_HandleSerData  [APP_TASK_STK_SIZE_HandleSerData    ];

                              /* TASK function */
/**
  * @brief Task definition
  */
APP_EXT_START     void  App_Task_START   (void *p_arg);
APP_EXT_COMM      void  App_Task_COMM    (void *p_arg);
APP_EXT_HCI       void  App_Task_HCI     (void *p_arg);
APP_EXT_DSTIN     void  App_Task_DSTIN   (void *p_arg);
APP_EXT_NORMAD    void  App_Task_NORMAD  (void *p_arg);
APP_EXT_ACAD      void  App_Task_ACAD    (void *p_arg);
APP_EXT_WORKFLOW  void  App_Task_WORKFLOW(void *p_arg);
APP_EXT_LOAD      void  App_Task_LOAD    (void *p_arg);
APP_EXT_RELAY     void  App_Task_RELAY   (void *p_arg);
APP_EXT_NETWORK   void  App_Task_NETWORK    (void *p_arg);
APP_EXT_START     void  App_Task_NETWORK_HandleCache    (void *p_arg);
APP_EXT_START     void  App_Task_NETWORK_HandleSerData  (void *p_arg);


/*$PAGE*/                      /**************EVENT******************/

/**
  * @brief EVENT definition
  */

                                  /* Sem x51 */
  /* EVENT--Sem definition*/
APP_EXT_START    OS_EVENT           *App_Sem_STARTSYNC;

APP_EXT_START    OS_EVENT           *App_Sem_INPUTCTRSTA;
APP_EXT_START    OS_EVENT           *App_Sem_INPUTTOUCH;
APP_EXT_START    OS_EVENT           *App_Sem_NORMADCTRSTA;
APP_EXT_START    OS_EVENT           *App_Sem_ACADCTRSTA;
APP_EXT_START    OS_EVENT           *App_Sem_RAWALARM;
APP_EXT_START    OS_EVENT           *App_Sem_OUTALARM;
APP_EXT_START    OS_EVENT           *App_Sem_GENSTATUS;
APP_EXT_START    OS_EVENT           *App_Sem_OUTPUTS;
APP_EXT_START    OS_EVENT           *App_Sem_WORKFLOW;
APP_EXT_START    OS_EVENT           *App_Sem_LOAD;
APP_EXT_START    OS_EVENT           *App_Sem_RTC;
APP_EXT_START    OS_EVENT           *App_Sem_HCI;
APP_EXT_START    OS_EVENT           *App_Sem_LCMTX;
APP_EXT_START    OS_EVENT           *App_Sem_WIFITX;

APP_EXT_START    OS_EVENT           *App_Sem_EEPROMHW;
APP_EXT_START    OS_EVENT           *App_Sem_EEPROMOP;
APP_EXT_START    OS_EVENT           *App_Sem_NetworkTX;
APP_EXT_START    OS_EVENT           *App_Sem_RS232TX;
APP_EXT_START    OS_EVENT           *App_Sem_RS485TX;
APP_EXT_START    OS_EVENT           *App_Sem_RTCADJ;
APP_EXT_START    OS_EVENT           *App_Sem_SMSReport;

APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE0  ;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE1  ;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE3  ;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE4  ;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE5  ;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE6  ;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE7  ;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE8  ;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE11 ;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE12 ;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE13 ;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE14 ;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE16 ;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE17 ;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE18 ;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE96 ;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE114;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE128;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE129;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE130;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE131;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE132;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE133;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE134;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE135;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE136;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE137;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE138;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE139;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE140;
APP_EXT_START    OS_EVENT           *App_Sem_PCFGPAGE219;


  /* EVENT--Mbox definition*/

                                  /* Mutex x0 */
  /* EVENT--Mutex definition*/

                                  /* Flag x10 */
  /* EVENT--Flag definition*/
APP_EXT_START    OS_FLAG_GRP        *App_Flags_HCI     ;
APP_EXT_START    OS_FLAG_GRP        *App_Flags_DSTIN   ;
APP_EXT_START    OS_FLAG_GRP        *App_Flags_NORMAD  ;
APP_EXT_START    OS_FLAG_GRP        *App_Flags_ACAD    ;
APP_EXT_START    OS_FLAG_GRP        *App_Flags_WORKFLOW;
APP_EXT_START    OS_FLAG_GRP        *App_Flags_LOAD    ;
APP_EXT_START    OS_FLAG_GRP        *App_Flags_RELAY   ;
APP_EXT_START    OS_FLAG_GRP        *App_Flags_EEPROM  ;
APP_EXT_START    OS_FLAG_GRP        *App_Flags_COMMUNI ;
APP_EXT_START    OS_FLAG_GRP        *App_Flags_NETWORK ;
APP_EXT_START    OS_FLAG_GRP        *App_Flags_EC20Cache ;

                                  /* Q x2 */
  /* EVENT--Q definition*/
APP_EXT_START    OS_EVENT           *App_Q_HANDLESERDATA;
APP_EXT_START     OS_EVENT          *App_Q_KEYFLOW;
APP_EXT_START     OS_EVENT          *App_Q_ACAD;

#define NumOfSerDataflowdata                      3
#define NumOfKeyflowdataQ                         4        /* Adjust during testing */
#define NumOfACRXdataQ                            5        /* Adjust during testing */

APP_EXT_START     void             *serDataflowdataMsg[NumOfSerDataflowdata];
APP_EXT_START     void             *KeyflowdataMsg[NumOfKeyflowdataQ];
APP_EXT_START     void             *ACRecdataMsg[NumOfACRXdataQ];

                                  /* Tmr */
/**
  * @brief Tmr definition
  */
APP_EXT_START     OS_TMR          *App_Tmr_TIMER01HZ;
APP_EXT_START     OS_TMR          *App_Tmr_TIMER10HZ;
APP_EXT_START     OS_TMR          *App_Tmr_TIMER20HZ;


/*$PAGE*/                      /**************Name******************/

/**
  * @brief TASKS/EVENT NAMES definition
  */
                              /* Task Name    */
#define  APP_TASK_NAME_START                       "STR_T"
#define  APP_TASK_NAME_COMM                       "COMM T"
#define  APP_TASK_NAME_HCI                         "HCI T"
#define  APP_TASK_NAME_DSTIN                     "DSTIN T"
#define  APP_TASK_NAME_NORMAD                   "NORMAD_T"
#define  APP_TASK_NAME_ACAD                       "ACAD_T"
#define  APP_TASK_NAME_WORKFLOW               "WORKFLOW_T"
#define  APP_TASK_NAME_LOAD                       "LOAD_T"
#define  APP_TASK_NAME_RELAY                     "RELAY_T"
#define  APP_TASK_NAME_WIFI                       "WIFI_T"

                              /* MBOX Name    */


                              /* SEM Name     */
#define  App_SEM_NAME_STARTSYNC              "STARTSYNC_S"
#define  App_SEM_NAME_INPUTCTRSTA          "INPUTCTRSTA_S"
#define  App_SEM_NAME_INPUTTOUCH            "INPUTTOUCH_S"
#define  App_SEM_NAME_NORMADCTRSTA        "NORMADCTRSTA_S"
#define  App_SEM_NAME_ACADCTRSTA            "ACADCTRSTA_S"
#define  App_SEM_NAME_RAWALARM                "RAWALARM_S"
#define  App_SEM_NAME_OUTALARM                "OUTALARM_S"
#define  App_SEM_NAME_GENSTATUS              "GENSTATUS_S"
#define  App_SEM_NAME_OUTPUTS                  "OUTPUTS_S"
#define  App_SEM_NAME_WORKFLOW                "WORKFLOW_S"
#define  App_SEM_NAME_LOAD                        "LOAD_S"
#define  App_SEM_NAME_RTC                          "RTC_S"
#define  App_SEM_NAME_HCI                          "HCI_S"
#define  App_SEM_NAME_LCMTX                      "LCMTX_S"
#define  App_SEM_NAME_WIFITX                    "WIFITX_S"
#define  App_SEM_NAME_SMSReport                    "SMS_S"
#define  App_SEM_NAME_PCFGPAGE0                 "PAGE0_S"
#define  App_SEM_NAME_PCFGPAGE1                 "PAGE1_S"
#define  App_SEM_NAME_PCFGPAGE3                 "PAGE3_S"
#define  App_SEM_NAME_PCFGPAGE4                 "PAGE4_S"
#define  App_SEM_NAME_PCFGPAGE5                 "PAGE5_S"
#define  App_SEM_NAME_PCFGPAGE6                 "PAGE6_S"
#define  App_SEM_NAME_PCFGPAGE7                 "PAGE7_S"
#define  App_SEM_NAME_PCFGPAGE8                 "PAGE8_S"
#define  App_SEM_NAME_PCFGPAGE11                "PAGE11_S"
#define  App_SEM_NAME_PCFGPAGE12                "PAGE12_S"
#define  App_SEM_NAME_PCFGPAGE13                "PAGE13_S"
#define  App_SEM_NAME_PCFGPAGE14                "PAGE14_S"
#define  App_SEM_NAME_PCFGPAGE16                "PAGE16_S"
#define  App_SEM_NAME_PCFGPAGE17                "PAGE17_S"
#define  App_SEM_NAME_PCFGPAGE18                "PAGE18_S"
#define  App_SEM_NAME_PCFGPAGE96                "PAGE96_S"
#define  App_SEM_NAME_PCFGPAGE114               "PAGE114_S"
#define  App_SEM_NAME_PCFGPAGE128               "PAGE128_S"
#define  App_SEM_NAME_PCFGPAGE129               "PAGE129_S"
#define  App_SEM_NAME_PCFGPAGE130               "PAGE130_S"
#define  App_SEM_NAME_PCFGPAGE131               "PAGE131_S"
#define  App_SEM_NAME_PCFGPAGE132               "PAGE132_S"
#define  App_SEM_NAME_PCFGPAGE133               "PAGE133_S"
#define  App_SEM_NAME_PCFGPAGE134               "PAGE134_S"
#define  App_SEM_NAME_PCFGPAGE135               "PAGE135_S"
#define  App_SEM_NAME_PCFGPAGE136               "PAGE136_S"
#define  App_SEM_NAME_PCFGPAGE137               "PAGE137_S"
#define  App_SEM_NAME_PCFGPAGE138               "PAGE138_S"
#define  App_SEM_NAME_PCFGPAGE139               "PAGE139_S"
#define  App_SEM_NAME_PCFGPAGE140               "PAGE140_S"
#define  App_SEM_NAME_PCFGPAGE219               "PAGE219_S"
#define  App_SEM_NAME_EEPROMHW                 "EEPROMHW_S"
#define  App_SEM_NAME_EEPROMOP                 "EEPROMOP_S"
#define  App_SEM_NAME_NetworkTX               "NetworkTX_S"
#define  App_SEM_NAME_RS232TX                   "RS232TX_S"
#define  App_SEM_NAME_RS485TX                   "RS485TX_S"
#define  App_SEM_NAME_RTCADJ                     "RTCADJ_S"


                              /* MUTEX Name   */

                              /* FLAGS Name   */
#define  App_FLAGS_NAME_HCI                      "HCI_Fl" 
#define  App_FLAGS_NAME_DSTIN                  "DSTIN_Fl" 
#define  App_FLAGS_NAME_NORMAD                "NORMAD_Fl" 
#define  App_FLAGS_NAME_ACAD                    "ACAD_Fl" 
#define  App_FLAGS_NAME_WORKFLOW            "WORKFLOW_Fl" 
#define  App_FLAGS_NAME_LOAD                    "LOAD_Fl"  
#define  App_FLAGS_NAME_RELAY                  "RELAY_Fl" 
#define  App_FLAGS_NAME_EEPROM                "EEPROM_Fl" 
#define  App_FLAGS_NAME_COMMUNI               "COMMUN_Fl" 
#define  App_FLAGS_NAME_WIFI                    "WIFI_Fl" 

                              /* Q Name       */
#define  App_Q_NAME_KEYFLOW                   "KEYFLOW_Q" 
#define  App_Q_NAME_ACAD                         "ACAD_Q"

                              /* TMR Name     */
#define  App_TMR_NAME_TIMER01HZ                   "1HZ_Tr"   
#define  App_TMR_NAME_TIMER10HZ                  "10HZ_Tr"   
#define  App_TMR_NAME_TIMER20HZ                 "20HZl_Tr"   



/*$PAGE*/#ifdef __cplusplus
}
#endif


#endif	/*	__TASK_CFG_H__	*/
